package cn.akwangl.prototype;

import org.springframework.beans.BeanUtils;

/**
 * 作者：阿坤
 * 创建时间：16:26 2019/8/15
 * 功能描述：原型拷贝客户端
 */
public class Client {

    public static void main(String[] args) {
        Prototype obj1 = new Prototype("阿坤", "你好！");
        // 设置引用类型
        obj1.setStudent(new Student("飞", 18));

        // 拷贝数据
        Prototype clone = obj1.clone();
        clone.setName("张三");
        // 设置引用类型的数据
        clone.setStudent(clone.getStudent().clone());
        clone.getStudent().setName("飞！");
        clone.getStudent().setAge(27);

        System.out.println("obj1" + obj1);
        System.out.println("clone" + clone);

        /**
         * 查看一下引用类型数据
         */
        System.out.println("obj1 的Student" + obj1.getStudent());
        System.out.println("clone 的Student" + clone.getStudent());

        /**
         * --------------------------Spring BeanUtils------------------------------
         */
        Prototype obj2 = new Prototype("阿坤2", "飞2！");
        obj2.setStudent(new Student("001", 18));

        Prototype obj3 = BeanUtils.instantiateClass(Prototype.class);
        BeanUtils.copyProperties(obj2,obj3);
        obj3.setName("阿伦");
        obj3.getStudent().setAge(600);

        /**
         * 使用Spring BeanUtils不会进行深拷贝
         */
        System.out.println("obj2 数据"+obj2);
        System.out.println("obj3 数据"+obj3);
    }
}
